// components/normal-Tabs/Tabs.js
const app = getApp()
Component({
    /**
     * 组件的属性列表
     */
    properties: {
        navData: {
            type: Array,
            value: []
        }
    },

    /**
     * 组件的初始数据
     */
    data: {
        currentTab: 0,
        navScrollLeft: 0,
        windowWidth: app.globalData.windowWidth
    },

    /**
     * 组件的方法列表
     */
    methods: {
        switchNav(event){
            var cur = event.currentTarget.dataset.current; 
            //每个tab选项宽度占1/5
            var singleNavWidth = this.data.windowWidth / 5;
            //tab选项居中                            
            this.setData({
                navScrollLeft: (cur - 2) * singleNavWidth
            })      
            if (this.data.currentTab == cur) {
                return false;
            } else {
                this.setData({
                    currentTab: cur
                })
            }
        },
        switchTab(event){
            var cur = event.detail.current;
            var singleNavWidth = this.data.windowWidth / 5;
            this.setData({
                currentTab: cur,
                navScrollLeft: (cur - 2) * singleNavWidth
            });
        }
    }
})
